Skip to content

fix(site): reject a --proxy port outside 1-65535 instead of silently misconfiguring - #280

Merged
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/site-proxy-port-range
Aug 3, 2026
Merged

fix(site): reject a --proxy port outside 1-65535 instead of silently misconfiguring#280
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/site-proxy-port-range

Conversation

@clawedassistant26

Copy link
Copy Markdown
Contributor

moshcode site <name> --proxy <port> validated the port with /^\d+$/. That accepts 0 and out-of-range numbers, and both then fail silently:

  • --proxy 0 passes the regex, but 0 is falsy downstream, so servePlan builds a static root server, not a reverse proxy. It reports the site as live.
  • --proxy 99999 passes the regex and writes proxy_pass http://127.0.0.1:99999; — a port that cannot exist. It also reports the site as live.

Every other port in the codebase is validated as 1-65535 (console --port, dns --port, dns --parking-port, all with the message needs a decimal integer from 1 to 65535). --proxy was the odd one out.

Before (unmodified main)

Driving the exported serveCommand with a stubbed writer:

--proxy 3000   exit=0  config=PROXY→3000                | blue.eggs → 127.0.0.1:3000
--proxy 0      exit=0  config=STATIC (no proxy_pass)     | blue.eggs → /srv/blue.eggs
--proxy 99999  exit=0  config=PROXY→99999                | blue.eggs → 127.0.0.1:99999

After

--proxy 3000   exit=0  config=PROXY→3000        (unchanged)
--proxy 0      exit=1  refused, nothing written
--proxy 99999  exit=1  refused, nothing written

Change

  • src/serve.mjs: validate --proxy as an integer in 1-65535, with the same message style the rest of the CLI uses.
  • test/serve.test.mjs: a regression test that 0, 99999, 70000, -1, abc and empty are refused with exit 1 and no config written, plus a control asserting a real port still installs the reverse proxy unchanged.

Full suite: 1214 tests, 1001 pass, 0 fail (1000→1001, one new test). No other files touched.

…misconfiguring

`moshcode site <name> --proxy <port>` validated the port with `^\d+$`, which
accepts 0 and out-of-range numbers. --proxy 0 is falsy downstream, so the site
silently dropped to a static root; --proxy 99999 wrote a proxy_pass to a port
that cannot exist. Both exited 0 and reported the site as live.

Validate the port as 1-65535, matching the range every other port takes here
(console --port, dns --port/--parking-port). Adds a regression test plus a
control that a real port still installs the reverse proxy unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ralyodio
ralyodio merged commit 7e4e07f into moshcoder:main Aug 3, 2026
4 checks passed
@ralyodio ralyodio mentioned this pull request Aug 4, 2026
ralyodio added a commit that referenced this pull request Aug 4, 2026
A Moshpit name now survives the TLS handshake without a per-name detour.
`dns trust <name>` installs the leaf a name serves, but only when its key
matches a pin the registry already published, and `dns start --trust-all`
does that as names resolve (#279, #281). Minor, not patch: two new ways to
invoke the tool.

Also carries two commands that used to report success they had not earned
-- `update --timer --install` when systemctl refused (#282), and
`site --proxy` with a port outside 1-65535 (#280).

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants